package com.yanqu.road.server.cmd.activity.huashigang;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.huashigang.HuaShiGangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.huashigang.HuaShiGangMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.PropertyHelper;

/**
 * @Author wpj
 * @Date 2020/10/7
 */
@Cmd(code = GameProtocol.S_HUA_SHI_GANG_OPEN_TREASURE_FROM_CROSS, desc = "从跨服获得打开花石纲藏宝的消息")
public class OpenTreasureFromCrossCmd extends AbstractCommand {
    String reward;
    boolean good;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        HuaShiGangProto.OpenTreasureFromCross msg = HuaShiGangProto.OpenTreasureFromCross.parseFrom(packet.getBytes());
        reward = msg.getReward();
        good = msg.getGood();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ActivityInfo activityInfo = HuaShiGangMgr.getActivityInfo();
        if (activityInfo != null) {
            player.getModule(CurrencyModule.class).addCurrency(PropertyHelper.parseStringToProperty(reward), eLogMoneyType.HuaShiGang, eLogMoneyType.HuaShiGangOpenTreasure);
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        HuaShiGangProto.OpenTreasureRespMsg.Builder builder = HuaShiGangProto.OpenTreasureRespMsg.newBuilder();
        builder.setRet(0);
        builder.setGood(good);
        builder.setReward(reward);
        player.sendPacket(ClientProtocol.U_HUA_SHI_GANG_OPEN_TREASURE, builder);
    }
}
